package com.zusmart.core.config.source;

import java.util.Map;

import com.zusmart.base.util.Assert;
import com.zusmart.core.config.support.AbstractConfigSource;

public class ConfigSourceForMap extends AbstractConfigSource {

	public static final String EXTENSION = "map";

	private final Map<String, String> mapping;

	public ConfigSourceForMap(String configFile, Map<String, String> mapping) {
		super(configFile, EXTENSION);
		Assert.isNull(mapping, "mapping must not be null");
		this.mapping = mapping;
	}

	@Override
	public boolean hasConfigData(String configName) {
		return this.mapping.containsKey(configName);
	}

	@Override
	public String getConfigData(String configName, String defaultData) {
		if (this.hasConfigData(configName)) {
			return this.mapping.get(configName);
		} else {
			return defaultData;
		}
	}

}